using System;
using UnityEngine;

namespace DanielSig.UnityExtensions
{
	public static class XTextAnchor
	{
		public static TextAnchor ToLower(this TextAnchor anchor)
		{
			switch(anchor)
			{
				case TextAnchor.MiddleLeft:		return TextAnchor.LowerLeft;
				case TextAnchor.MiddleCenter:	return TextAnchor.LowerCenter;
				case TextAnchor.MiddleRight:	return TextAnchor.LowerRight;

				case TextAnchor.UpperLeft:		return TextAnchor.LowerLeft;
				case TextAnchor.UpperCenter:	return TextAnchor.LowerCenter;
				case TextAnchor.UpperRight:		return TextAnchor.LowerRight;
				default: return anchor;
			}
		}
		public static TextAnchor ToMiddle(this TextAnchor anchor)
		{
			switch(anchor)
			{
				case TextAnchor.LowerLeft:		return TextAnchor.MiddleLeft;	
				case TextAnchor.LowerCenter:	return TextAnchor.MiddleCenter;
				case TextAnchor.LowerRight:		return TextAnchor.MiddleRight;

				case TextAnchor.UpperLeft:		return TextAnchor.MiddleLeft;
				case TextAnchor.UpperCenter:	return TextAnchor.MiddleCenter;
				case TextAnchor.UpperRight:		return TextAnchor.MiddleRight;
				default: return anchor;
			}
		}
		public static TextAnchor ToUpper(this TextAnchor anchor)
		{
			switch(anchor)
			{
				case TextAnchor.LowerLeft:		return TextAnchor.UpperLeft;	
				case TextAnchor.LowerCenter:	return TextAnchor.UpperCenter;
				case TextAnchor.LowerRight:		return TextAnchor.UpperRight;

				case TextAnchor.MiddleLeft:		return TextAnchor.UpperLeft;
				case TextAnchor.MiddleCenter:	return TextAnchor.UpperCenter;
				case TextAnchor.MiddleRight:	return TextAnchor.UpperRight;
				default: return anchor;
			}
		}
		public static TextAnchor ToLeft(this TextAnchor anchor)
		{
			switch(anchor)
			{
				case TextAnchor.LowerCenter:	return TextAnchor.LowerLeft;
				case TextAnchor.LowerRight:		return TextAnchor.LowerLeft;

				case TextAnchor.MiddleCenter:	return TextAnchor.MiddleLeft;
				case TextAnchor.MiddleRight:	return TextAnchor.MiddleLeft;

				case TextAnchor.UpperCenter:	return TextAnchor.UpperLeft;
				case TextAnchor.UpperRight:		return TextAnchor.UpperLeft;
				default: return anchor;
			}
		}
		public static TextAnchor ToCenter(this TextAnchor anchor)
		{
			switch(anchor)
			{
				case TextAnchor.LowerLeft:		return TextAnchor.LowerCenter;
				case TextAnchor.LowerRight:		return TextAnchor.LowerCenter;

				case TextAnchor.MiddleLeft:		return TextAnchor.MiddleCenter;
				case TextAnchor.MiddleRight:	return TextAnchor.MiddleCenter;

				case TextAnchor.UpperLeft:		return TextAnchor.UpperCenter;
				case TextAnchor.UpperRight:		return TextAnchor.UpperCenter;
				default: return anchor;
			}
		}
		public static TextAnchor ToRight(this TextAnchor anchor)
		{
			switch(anchor)
			{
				case TextAnchor.LowerLeft:		return TextAnchor.LowerRight;
				case TextAnchor.LowerCenter:	return TextAnchor.LowerRight;

				case TextAnchor.MiddleLeft:		return TextAnchor.MiddleRight;
				case TextAnchor.MiddleCenter:	return TextAnchor.MiddleRight;

				case TextAnchor.UpperLeft:		return TextAnchor.UpperRight;
				case TextAnchor.UpperCenter:	return TextAnchor.UpperRight;
				default: return anchor;
			}
		}
		public static TextAnchor FlipHorizontal(this TextAnchor anchor)
		{
			switch(anchor)
			{
				case TextAnchor.LowerLeft:		return TextAnchor.LowerRight;
				case TextAnchor.LowerRight:		return TextAnchor.LowerLeft;

				case TextAnchor.MiddleLeft:		return TextAnchor.MiddleRight;
				case TextAnchor.MiddleRight:	return TextAnchor.MiddleLeft;

				case TextAnchor.UpperLeft:		return TextAnchor.UpperRight;
				case TextAnchor.UpperRight:		return TextAnchor.UpperLeft;
				default: return anchor;
			}
		}
		public static TextAnchor FlipVertical(this TextAnchor anchor)
		{
			switch(anchor)
			{
				case TextAnchor.LowerCenter:	return TextAnchor.UpperCenter;
				case TextAnchor.LowerLeft:		return TextAnchor.UpperLeft;
				case TextAnchor.LowerRight:		return TextAnchor.UpperRight;

				case TextAnchor.UpperCenter:	return TextAnchor.LowerCenter;
				case TextAnchor.UpperLeft:		return TextAnchor.LowerLeft;
				case TextAnchor.UpperRight:		return TextAnchor.LowerRight;
				default: return anchor;
			}
		}
		public static TextAnchor RotateCW(this TextAnchor anchor, int times = 1)
		{
			if(times > 0)
			{
				if(times > 1) anchor = anchor.RotateCW(times-1);
				switch(anchor)
				{
					case TextAnchor.LowerRight:		return TextAnchor.LowerCenter;
					case TextAnchor.LowerCenter:	return TextAnchor.LowerLeft;
					case TextAnchor.LowerLeft:		return TextAnchor.MiddleLeft;
					case TextAnchor.MiddleLeft:		return TextAnchor.UpperLeft;
					case TextAnchor.UpperLeft:		return TextAnchor.UpperCenter;
					case TextAnchor.UpperCenter:	return TextAnchor.UpperRight;
					case TextAnchor.UpperRight:		return TextAnchor.MiddleRight;
					case TextAnchor.MiddleRight:	return TextAnchor.LowerRight;
					default: return anchor;
				}
			}
			else if(times < 0)
			{
				if(times < -1) anchor = anchor.RotateCW(times+1);
				switch(anchor)
				{
					case TextAnchor.LowerRight:		return TextAnchor.MiddleRight;
					case TextAnchor.MiddleRight:	return TextAnchor.UpperRight;
					case TextAnchor.UpperRight:		return TextAnchor.UpperCenter;
					case TextAnchor.UpperCenter:	return TextAnchor.UpperLeft;
					case TextAnchor.UpperLeft:		return TextAnchor.MiddleLeft;
					case TextAnchor.MiddleLeft:		return TextAnchor.LowerLeft;
					case TextAnchor.LowerLeft:		return TextAnchor.LowerCenter;
					case TextAnchor.LowerCenter:	return TextAnchor.LowerRight;
					default: return anchor;
				}
			}
			return anchor;
		}
		public static TextAnchor RotateCCW(this TextAnchor anchor, int times = 1)
		{
			return anchor.RotateCW(-times);
		}
		public static TextAnchor Rotate180(this TextAnchor anchor)
		{
			return anchor.RotateCW(2);
		}
	}
}

